Keeping STAMPS_DIR between CI builds?
I build OpenEmbedded on a CI machine (GitLab runner). Between the individual builds, I keep only the DL_DIR and SSTATE_DIR directories. So if nothing has changed between two builds, I see that mainly setscene tasks are executed.
In one recipe (the "main" application of our embedded product), I have a special task (between do_build and do_install) which "stamps" the build number of the CI system (increments on every build) into a special section of the executable. The idea is not to run the (costly) do_build step on every CI run:
do_stamp() {
[ -f myexe.orig ] || cp myexe myexe.orig
# Retrieve original VERSION section size
${OBJCOPY} --dump-section VERSION=myexe.version myexe.orig
SIZE=$(wc -c < myexe.version)
# Replace VERSION section (ensuring the same section size)
echo ${MY_VERSION}-${MY_BUILD_ID} > myexe.version
truncate -s ${SIZE} myexe.version
${OBJCOPY} --update-section VERSION=myexe.version myexe.orig myexe
}do_stamp[dirs] = "${B}"
addtask stamp after do_compile before do_install
This works fine on my local machine (here I don't delete anything between two bitbake runs): After changing MY_BUILD_ID in my local.conf, in the next bitbake run only the do_stamp (and the following) tasks are rebuild.
But on the CI system, all tasks of my applications recipe are rebuild (starting from "do_fetch"). This affects only my application's recipe, for all other targets (where no task input has changed), only the setscene tasks are run.
Summary:
---------
1. Only build id is incremented (but build tree is kept):do_stamp (and following tasks) are run (as desired)
2. Build id is not changed, but build tree is deleted:
only setscene tasks are run (as desired)
3. Build id is incremented AND build tree is deleted full applications recipe is run (starting with do_fetch)
I already found out, that this is somehow related to deleting the STAMPS_DIR directory (what I normally do on the CI system). It seems that the stamps are not required as long as no input of a recipe has changed. But as soon as an input of a single tasks changed, the full recipe is rebuild if no stamps are present.
So what is the best practice for the CI build? Should I keep the STAMPS_DIR between builds (as I do with DL_DIR and SSTATE_DIR), or is there a better option if I want to avoid rebuilding the whole recipe?
regards,
Christian
_______________________________________________________
Christian
Eggers
Software Engineer
ARRI
Arnold & Richter Cine Technik GmbH & Co. Betriebs KG Arriweg 17,
83071
Stephanskirchen
www.arri.com
+49 8036 3009-3118
[email protected]
Get all the latest information from www.arri.com, Facebook, Twitter, Instagram, LinkedIn and YouTube and X.
Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRA 57918 Persönlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRB 54477 Geschäftsführer: Dr. Matthias Erb (Chairman); Lars Weyer; Stephan Schenk; Walter Trauninger
Your description shows that everything works as intended. If something needs artefacts in ${B} then do_compile has to run at least once to populate ${B}. Preserving ${STAMPS_DIR} would clash with that and isn't going to work. And do_compile isn't sstate-enabled, so there's no shortcut that way.
I'd suggest that instead of embedding any build id data into the binary from its recipe, you can do the same step when building the image. There are hooks for this, e.g. ROOTFS_POSTPROCESS_COMMAND.
Alex
Quoted 117 lines · Christian Eggers
I build OpenEmbedded on a CI machine (GitLab runner). Between the individual builds,
I keep only theDL_DIRandSSTATE_DIRdirectories. So if nothing has changed between
two builds, I see that mainly setscene tasks are executed.In one recipe (the "main" application of our embedded product), I have a special task
(betweendo_buildanddo_install) which "stamps" the build number of the CI system
(increments on every build) into a special section of the executable. The idea is not
to run the (costly)do_buildstep on every CI run:
do_stamp(){
[ -f myexe.orig ] || cp myexe myexe.orig
# Retrieve original VERSION section size
${OBJCOPY} --dump-section VERSION=myexe.version myexe.orig SIZE=$(wc -c < myexe.version)
# Replace VERSION section (ensuring the same section size) echo ${MY_VERSION}-${MY_BUILD_ID} > myexe.version truncate -s ${SIZE} myexe.version
${OBJCOPY} --update-section VERSION=myexe.version myexe.orig myexe }
do_stamp[dirs] = "${B}"
addtask stamp afterdo_compilebeforedo_installThis works fine on my local machine (here I don't delete anything between two
bitbake runs): After changingMY_BUILD_IDin my local.conf, in the next bitbake
run only thedo_stamp(and the following) tasks are rebuild.But on the CI system, all tasks of my applications recipe are rebuild (starting
from "do_fetch"). This affects only my application's recipe, for all other targets (where no task input has changed), only the setscene tasks are run.Summary:
---------
1. Only build id is incremented (but build tree is kept):do_stamp(and following tasks) are run (as desired)2. Build id is not changed, but build tree is deleted:
only setscene tasks are run (as desired)3. Build id is incremented AND build tree is deleted full applications recipe is run (starting with
do_fetch)I already found out, that this is somehow related to deleting the
STAMPS_DIR
directory (what I normally do on the CI system). It seems that the stamps are not required as long as no input of a recipe has changed. But as soon as an input of a single tasks changed, the full recipe is rebuild if no stamps are present.So what is the best practice for the CI build? Should I keep the
STAMPS_DIRbetween builds (as I do withDL_DIRandSSTATE_DIR), or is there a better option
if I want to avoid rebuilding the whole recipe?regards,
Christian_______________________________________________________ Christian
Eggers
Software Engineer
ARRI
Arnold & Richter Cine Technik GmbH & Co. Betriebs KG Arriweg 17 ,
83071
Stephanskirchen
www.arri.com<http://www.arri.com/>
+49 8036 3009-3118 <+49%208036%203009-3118>
[email protected]
[image: SkyPanel X] <https://www.arri.com/skypanelx>
Get all the latest information from www.arri.com, Facebook
<https://www.facebook.com/TeamARRI>, Twitter
<https://twitter.com/ARRIChannel>, Instagram
<https://www.instagram.com/arri/>, LinkedIn
<https://www.linkedin.com/company/arri> and YouTube
<https://www.youtube.com/user/ARRIChannel> and X
<https://twitter.com/ARRIChannel>.Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: München ‑ Registergericht: Amtsgericht München ‑ Handelsregisternummer: HRA 57918 Persönlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: München ‑ Registergericht: Amtsgericht München ‑ Handelsregisternummer: HRB 54477
Geschäftsführer: Dr. Matthias Erb (Chairman); Lars Weyer; Stephan Schenk; Walter Trauninger
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#15559):
https://lists.openembedded.org/g/bitbake-devel/message/15559
Mute This Topic: https://lists.openembedded.org/mt/102746583/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Hi Alex,
Quoted 5 lines · Alexander Kanavin
Your description shows that everything works as intended. If something needs artefacts in ${B} then
do_compilehas to run at least once to populate ${B}. Preserving ${STAMPS_DIR} would clash with that and isn't going to work. Anddo_compileisn't sstate-enabled, so there's no shortcut that way.
that sounds like not every task's output goes to the shared state cache (is there documentation about this?). As do_compile doesn't go to cache, all previous tasks (also not cached?) have to be rerun.
Would it make sense to put the result of do_compile into the cache for my particular recipe?
Quoted 3 lines
I'd suggest that instead of embedding any build id data into the binary from its recipe, you can do the same step when building the image. There are hooks for this, e.g.
ROOTFS_POSTPROCESS_COMMAND.
Of course this is much more straight forward (and what I already do). Be for some use cases (automatic testing), we handle with individual IPK files / executables rather than with complete rootfs images. For this use case it would be helpful if the application could "identify" itself.
regards,
Christian
Quoted 3 lines
Alex
_______________________________________________________
Christian
Eggers
Software Engineer
ARRI
Arnold & Richter Cine Technik GmbH & Co. Betriebs KG Arriweg 17,
83071
Stephanskirchen
www.arri.com
+49 8036 3009-3118
[email protected]
Get all the latest information from www.arri.com, Facebook, Twitter, Instagram, LinkedIn and YouTube and X.
Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRA 57918 Persönlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRB 54477 Geschäftsführer: Dr. Matthias Erb (Chairman); Lars Weyer; Stephan Schenk; Walter Trauninger
Quoted 68 lines · Christian Eggers
Quoted 67 lines
I build OpenEmbedded on a CI machine (GitLab runner). Between the individual builds,
I keep only theDL_DIRandSSTATE_DIRdirectories. So if nothing has changed between
two builds, I see that mainly setscene tasks are executed.In one recipe (the "main" application of our embedded product), I have a special task
(betweendo_buildanddo_install) which "stamps" the build number of the CI system
(increments on every build) into a special section of the executable. The idea is not
to run the (costly)do_buildstep on every CI run:
do_stamp(){
[ -f myexe.orig ] || cp myexe myexe.orig
# Retrieve original VERSION section size
${OBJCOPY} --dump-section VERSION=myexe.version myexe.orig SIZE=$(wc -c < myexe.version)
# Replace VERSION section (ensuring the same section size) echo ${MY_VERSION}-${MY_BUILD_ID} > myexe.version truncate -s ${SIZE} myexe.version
${OBJCOPY} --update-section VERSION=myexe.version myexe.orig myexe }
do_stamp[dirs] = "${B}"
addtask stamp afterdo_compilebeforedo_installThis works fine on my local machine (here I don't delete anything between two
bitbake runs): After changingMY_BUILD_IDin my local.conf, in the next bitbake
run only thedo_stamp(and the following) tasks are rebuild.But on the CI system, all tasks of my applications recipe are rebuild (starting
from "do_fetch"). This affects only my application's recipe, for all other targets (where no task input has changed), only the setscene tasks are run.Summary:
---------
1. Only build id is incremented (but build tree is kept):do_stamp(and following tasks) are run (as desired)2. Build id is not changed, but build tree is deleted:
only setscene tasks are run (as desired)3. Build id is incremented AND build tree is deleted full applications recipe is run (starting with
do_fetch)I already found out, that this is somehow related to deleting the
STAMPS_DIR
directory (what I normally do on the CI system). It seems that the stamps are not required as long as no input of a recipe has changed. But as soon as an input of a single tasks changed, the full recipe is rebuild if no stamps are present.So what is the best practice for the CI build? Should I keep the
STAMPS_DIRbetween builds (as I do withDL_DIRandSSTATE_DIR), or is there a better option
if I want to avoid rebuilding the whole recipe?regards,
Christian
Quoted 5 lines · Christian Eggers
that sounds like not every task's output goes to the shared state cache (is there documentation about this?). As
do_compiledoesn't go to cache, all previous tasks (also not cached?) have to be rerun.
I'm not sure if there is, but for the actual binary artefacts the first task that does put things into sstate is do_package.
Quoted 4 lines
Would it make sense to put the result of
do_compileinto the cache for my particular recipe?
No. You would deviate from standard yocto practices too far here. Your goal should be to write as little custom code as possible, and stay as close to standard, understandable builds as you can.
Quoted 5 lines
Quoted 4 lines
I'd suggest that instead of embedding any build id data into the binary from its recipe, you can do the same step when building the image. There are hooks for this, e.g.
ROOTFS_POSTPROCESS_COMMAND.
Quoted 8 lines
Of course this is much more straight forward (and what I already do). Be for
some use cases (automatic testing), we handle with individual IPK files / executables
rather than with complete rootfs images. For this use case it would be helpful
if the application could "identify" itself.
But then you can perhaps write the build id into ipk metadata rather than the binary itself? I don't remember if there are convenient hooks for that, but that would allow direct shortcut to package_write_ipk if nothing else changed, as that would take do_package from sstate.
Alex
Quoted 11 lines · Christian Eggers
Quoted 8 lines · Alexander Kanavin
Your description shows that everything works as intended. If something
needs artefacts in ${B} thendo_compilehas to run at least once to populate ${B}. Preserving ${STAMPS_DIR} would clash with that and isn't
going to work. Anddo_compileisn't sstate-enabled, so there's no shortcut
that way.
Quoted 3 lines
that sounds like not every task's output goes to the shared state cache (is there documentation about this?). As
do_compiledoesn't go to cache, all previous tasks (also not cached?) have to be rerun.
SSTATETASKS gives a hint about which ones write to sstate. It doesn't make sense for everything to go there as the computation to recreate some things is similar to that of storing it, or storage is large and not often used, therefore not cost effective.
Quoted 2 lines
Would it make sense to put the result of
do_compileinto the cache for my particular recipe?
You could create an sstate task which stored the binary, which would work out very similar to the way do_deploy works. do_deploy would be the simplest example we have.
I would caution that sstate tasks aren't "easy" and the system does have to have knowledge of when to run dependent tasks and when not to so there are complications in making them work accurately. It isn't documented for that reason.
Regardless, keeping STAMPS_DIR around is a really bad idea unless you really know what you're doing.
Quoted 6 lines
Quoted 5 lines
I'd suggest that instead of embedding any build id data into the binary
from its recipe, you can do the same step when building the image. There
are hooks for this, e.g.ROOTFS_POSTPROCESS_COMMAND.
Quoted 7 lines
Of course this is much more straight forward (and what I already do). Be for
some use cases (automatic testing), we handle with individual IPK files / executables
rather than with complete rootfs images. For this use case it would be helpful
if the application could "identify" itself.
You could embed the ID into a file in the package instead of the binary itself but that doesn't solve the individual binary challenge. You could record the checksum of the binary and have a mapping maintained the other way?
Cheers,
Richard
Hi Richard,
Quoted 24 lines · Richard Purdie
Quoted 11 lines · Christian Eggers
Quoted 8 lines · Alexander Kanavin
Your description shows that everything works as intended. If something
needs artefacts in ${B} thendo_compilehas to run at least once to populate ${B}. Preserving ${STAMPS_DIR} would clash with that and isn't
going to work. Anddo_compileisn't sstate-enabled, so there's no shortcut
that way.Quoted 3 lines
that sounds like not every task's output goes to the shared state cache (is there documentation about this?). As
do_compiledoesn't go to cache, all previous tasks (also not cached?) have to be rerun.SSTATETASKS gives a hint about which ones write to sstate. It doesn't make sense for everything to go there as the computation to recreate some things is similar to that of storing it, or storage is large and not often used, therefore not cost effective.
Quoted 2 lines
Would it make sense to put the result of
do_compileinto the cache for my particular recipe?
Quoted 8 lines
You could create an sstate task which stored the binary, which would work out very similar to the way
do_deployworks.do_deploywould be the simplest example we have.I would caution that sstate tasks aren't "easy" and the system does have to have knowledge of when to run dependent tasks and when not to so there are complications in making them work accurately. It isn't documented for that reason.
although I have been warned, I couldn't resist trying to add the do_compile task of my recipe to the sstate cache after finding the docs here:
https://docs.yoctoproject.org/overview-manual/concepts.html#shared-state
But adding do_compile seems to eat children, I got error messages like
ERROR: myapp-3.0.12+gitAUTOINC+c80b310bcd-r0 do_prepare_recipe_sysroot: The sstate manifest for task 'kern-tools-native:populate_sysroot' (multilib variant '') could not be found. The pkgarchs considered were: x86_64, x86_64_opensuseleap-15.5.
But none of these manifests exists:
/build/devel/tmp/sstate-control/manifest-x86_64-kern-tools-native.populate_sysroot /build/devel/tmp/sstate-control/manifest-x86_64_opensuseleap-15.5-kern-tools-native.populate_sysroot
After having learned that only do_package goes to the cache, I tried to squeeze my do_stamp task between do_package and do_package_write_ipk:
do_stamp() {
[ -f myapp.orig ] || cp myapp myapp.orig
# Retrieve original section size
${OBJCOPY} --dump-section VERSION=myapp.version myapp.orig
SIZE=$(stat -c '%s' myapp.version)
# Update section (ensuring the same section size)
echo ${SW_VERSION}-${CI_PIPELINE_ID} > myapp.version
truncate -s ${SIZE} myapp.version
${OBJCOPY} --update-section VERSION=myapp.version myapp.orig myapp
rm myapp.orig myapp.version
}do_stamp[dirs] = "${PKGDEST}/${PN}${bindir}"
addtask stamp after do_prepare_recipe_sysroot do_package before do_packagedata
I am not sure whether this will hit back like a boomerang some day later, but first tests seem to be promising. I needed some tries to figure out where exactly (image, package, packages-split) I have to apply my "binary patch".
Quoted 17 lines
Regardless, keeping
STAMPS_DIRaround is a really bad idea unless you really know what you're doing.Quoted 6 lines
Quoted 5 lines
I'd suggest that instead of embedding any build id data into the binary
from its recipe, you can do the same step when building the image. There
are hooks for this, e.g.ROOTFS_POSTPROCESS_COMMAND.Quoted 7 lines
Of course this is much more straight forward (and what I already do). Be for
some use cases (automatic testing), we handle with individual IPK files / executables
rather than with complete rootfs images. For this use case it would be helpful
if the application could "identify" itself.
Quoted 4 lines
You could embed the ID into a file in the package instead of the binary itself but that doesn't solve the individual binary challenge. You could record the checksum of the binary and have a mapping maintained the other way?
I think this is what GNU build-id already provides (which would also be compatible with reproducible builds). But most of my team voted for having the version and CI id inside the executable.
In contrast to putting these into the rootfs (either by a post rootfs hook or by a separate package), embedding the version information into the executable covers both, CI builds (by bitbake) and local builds (SDK + cmake).
regards,
Christian
_______________________________________________________
Christian
Eggers
Software Engineer
ARRI
Arnold & Richter Cine Technik GmbH & Co. Betriebs KG Arriweg 17,
83071
Stephanskirchen
www.arri.com
+49 8036 3009-3118
[email protected]
Get all the latest information from www.arri.com, Facebook, Twitter, Instagram, LinkedIn and YouTube and X.
Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRA 57918 Persönlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRB 54477 Geschäftsführer: Dr. Matthias Erb (Chairman); Lars Weyer; Stephan Schenk; Walter Trauninger